﻿using System.Windows;
using XAMLStylePad.Models;
using System.Collections.Generic;
using FireFly;
using System.Collections;

namespace XAMLStylePad.ViewModels
{
    public class ResourceDictionaryViewModel : XamlViewModelBase<ResourceDictionaryModel>
    {
        public ResourceDictionaryViewModel(ResourceDictionaryModel resources) : base(resources)
        {
        }

        #region Styles
        public CollectionViewModel<Style, StyleViewModel> Styles
        {
            get
            {
                if(_Styles == null)
                {
                    _Styles = new CollectionViewModel<Style, StyleViewModel>(Model.Styles, style =>
                    {
                        return new StyleViewModel(style)
                        {
                            ResourceKey = Model.GetValuesKey(style)
                        };
                    })
                    {
                        DisplayName = "Styles",
                        Parent = this
                    };
                }
                return _Styles;
            }
        }
        CollectionViewModel<Style, StyleViewModel> _Styles;
        #endregion

        #region Templates
        public CollectionViewModel<FrameworkTemplate, TemplateViewModel> Templates
        {
            get
            {
                if(_Templates == null)
                {
                    _Templates = new CollectionViewModel<FrameworkTemplate, TemplateViewModel>(Model.Templates, template =>
                    {
                        return new TemplateViewModel(template)
                        {
                            ResourceKey = Model.GetValuesKey(template)
                        };
                    })
                    {
                        DisplayName = "Templates",
                        Parent = this
                    };
                }
                return _Templates;
            }
        }
        CollectionViewModel<FrameworkTemplate, TemplateViewModel> _Templates;
        #endregion

        #region overrides
        public override string DisplayName
        {
            get
            {
                return Model.FileName;
            }
        }
        #endregion

        // command


        public override ICollection VisualChildren
        {
            get
            {
                return ViewModelService.Instance.CombineVisualChildren(Styles, Templates);
            }
        }
    }
}
